package com.example.helloworld.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Region;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class CustomView extends View {

	private Paint paint;
	
	public CustomView(Context context) {
		super(context);
		
		paint =	new Paint();
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(null);
		
		paint.setStyle(Style.FILL);
		paint.setColor(Color.RED);
		canvas.drawRect(10, 10, 100, 100, paint);
		
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(2.0F);
		paint.setColor(Color.GREEN);
		canvas.drawRect(10, 10, 100, 100, paint);
		
		paint.setStyle(Style.FILL);
		paint.setARGB(128, 0, 0, 255);
		canvas.drawRect(120, 10, 210, 100, paint);
		
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(3.0F);
		paint.setPathEffect(new DashPathEffect(new float[] {5, 5}, 1));
		paint.setColor(Color.GREEN);
		canvas.drawRect(120, 10, 210, 100, paint);
		
		paint =	new Paint();
		
		paint.setColor(Color.MAGENTA);
		canvas.drawCircle(50, 160, 40, paint);
		
		paint.setAntiAlias(true);
		canvas.drawCircle(160, 160, 40, paint);
		
		paint.setStyle(Style.STROKE);
		paint.setStrokeWidth(1);
		paint.setColor(Color.MAGENTA);
		paint.setTextSize(30);
		canvas.drawText("Text (Stroke)", 20, 260, paint);
		
		paint.setStyle(Style.FILL);
		paint.setTextSize(30);
		canvas.drawText("Text (Fill)", 20, 320, paint);

		paint.setStyle(Style.STROKE);
		paint.setColor(Color.BLACK);
		canvas.drawRect(220, 240, 320, 340, paint);
		
		canvas.clipRect(220, 240, 250, 270, Region.Op.REPLACE);
		paint.setStyle(Style.FILL);
		paint.setColor(Color.RED);
		canvas.drawRect(220, 240, 320, 340, paint);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			Toast.makeText(super.getContext(), "MotionEvent.ACTION_DOWN : " + event.getX() + "," + event.getY(), 1000).show();
		}
		
		return super.onTouchEvent(event);
	}

}
